package com.we823.project.repository.service.product;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.we823.project.model.product.PlanModel;
import com.we823.project.repository.dao.product.PlanRepository;
import com.we823.project.repository.service.AbstractBaseService;

@Service("planService")
public class PlanService extends AbstractBaseService<PlanModel> {

	private PlanRepository planRepository;
	
	@Autowired
	public PlanService(PlanRepository planRepository) {
		super(planRepository);
		this.planRepository = planRepository;
	}
	
	public Long getMaxId(){
		Long id = planRepository.getMaxId();
		return id==null ? 1 : (id+1);
	}

	public Map<Integer, PlanModel> map() {
		List<PlanModel> planModels = this.findAll();
		if(planModels!=null) {
			Map<Integer, PlanModel> map = new HashMap<Integer, PlanModel>();
			for (PlanModel planModel : planModels) {
				map.put(planModel.getId(), planModel);
			}
			return map;
		}
		return null;
	}

}
